<?php
/* $Id$ */

require_once "template/BasicTemplateProcessor.class.php";

class BaseLibrary {

	private $tpl_processor_class			= null;

	private $extension_neededExtensions_arr		= null;

	private $die_message_html	= "<p>({baselibrary_libClassName}) {baselibrary_die_message}</p>";

	function BaseLibrary( $libClassName, $neededExtensions_arr ) {

		$this->tpl_processor_class	= new BasicTemplateProcessor();
		$this->tpl_processor_class->registerKeyword( "{baselibrary_libClassName}", $libClassName );
	
		if ( $neededExtensions_arr != null )
			$this->extension_setNeededExtensions( $neededExtensions_arr );

	}

	function get_libClassName() {
		return $this->libClassName;
	}

	function getFlattened_string ( $array ) {
		$string = "";
		foreach( $array as $value ) {
			$string .= $value." ";
		}
		trim($string);

		return $string;
	}

	function dieByError( $die_message ) {

		$this->tpl_processor_class->registerKeyword("{baselibrary_die_message}", 
			$this->tpl_processor_class->processString( $die_message )
		 );

		die ( $this->tpl_processor_class->processString( $this->die_message_html ) );

	}

	function getTemplateProcessor_class() {
		return $this->tpl_processor_class;
	}

	function setTemplateProcessor_class( $class ) {
		$this->tpl_processor_class = $class;
	} 

	function extension_isLoaded( $extension ) {
		return extension_loaded( $extension );
	}

	function extension_setNeededExtensions( $extension_arr ) {
		$this->extension_neededExtensions_arr = $extension_arr;

		$this->tpl_processor_class->registerKeyword(
			"{baselibrary_extension_listAsString}", 
			$this->getFlattened_string( $extension_arr ) 
		);
	}

	function extension_getNeededExtensions_arr() {
		return $this->extension_neededExtensions_arr;
	}

	function extension_searchForMultipleExtensions_return_number() {
		
		if ( $this->extension_getNeededExtensions_arr() == null )
			return 0;

		$counter = 0;
		foreach( $this->extension_getNeededExtensions_arr() as $searched_extension ) {
			foreach( get_loaded_extensions() as $loaded_extension ) {
				
				if ( $searched_extension == $loaded_extension ) 
					$counter++;				
			}
		}

		return $counter;
	}

	function base_environment_extensions_neededAtLeastOrDie_html( $neededAtLeastNumber, $die_message ) {

		/* Umgebungs Abfrage */
		if (  $this->extension_searchForMultipleExtensions_return_number() < $neededAtLeastNumber ) {
			$this->dieByError( $die_message );
		} 

	}

	function base_environment_phpversion_isAtLeastVersionNumber( $versionNumber ) {
		return !(version_compare( phpversion(), $versionNumber ) === -1);
	}

	function base_environment_phpversion_neededAtLeastOrDie_html( $neededAtLeastNumber, $die_message ) {

		if ( !$this->base_environment_phpversion_isAtLeastVersionNumber( $neededAtLeastNumber ) ) {
			$this->dieByError( $die_message );
		} 	

	}

}




?>